import java.io.*;

public class NumbersAction {

	public static int[] getNewArray(int length) throws Exception{
		if(length>0){
			int numbers[] = new int[length];
			for (int i=0;i<length;i++) numbers[i] = (int) Math.floor(Math.random() * length);
			return numbers;
		}else{
			throw new Exception("WrongNumber");
		}
	}
	
	public static void writeToFile(String fileName, int[] array) throws IOException{
		FileOutputStream outFile = new FileOutputStream(fileName);		
		ObjectOutputStream oos = new ObjectOutputStream(outFile);
		oos.writeObject(array);		
		oos.close();
		outFile.close();
	}
	
	public static int[] readFromFile(String fileName) throws IOException, ClassNotFoundException{
		FileInputStream inFile = new FileInputStream(fileName);
		ObjectInputStream ois = new ObjectInputStream(inFile);
		int[] array = (int[]) ois.readObject();
		ois.close();
		inFile.close();
		return array;

	}
	
}
